home *** CD-ROM | disk | FTP | other *** search
/ Mastering Public Speaking / Mastering Public Speaking.iso / pc / Click Here.exe / Click Here.dxr / Internal_26_Zoom In-Out.ls < prev    next >
Encoding:
Text File  |  2003-05-13  |  5.4 KB  |  165 lines

  1. property pSprite, pSpriteRect, pStart, pActive, pStartRect, pDestRect, pDiffRect, pCompleteCycles, pText, pZoomed, pAuto, pTargetH, pTargetV, pCycles, pPeriodBase, pPeriod
  2.  
  3. on getBehaviorDescription me
  4.   return "ZOOM IN/OUT" & RETURN & RETURN & "Gives the appearance of a sprite zooming in (getting larger) or zooming out (smaller). " & "Can be used with animated GIF, bitmap, Flash, QuickTime, text, and vector shape sprites." & RETURN & RETURN & "Place the sprite in its desired zoomed-in position, then add the behavior to the sprite. " & "Choose whether the sprite should zoom in or out, when the zooming should start, the coordinates for the zoomed-out sprite, the number of times it should zoom, and how fast it should zoom. " & "The default zoomed-out position is the center of the sprite." & RETURN & RETURN & "The zoom can be activated automatically in the first frame, by a click on the sprite, or by sending the sprite a mZoomActivate message. " & "See the Notes for Developers in the script for information on this method." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "animated GIF, bitmap, Flash, QuickTime, text, vector shape" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Zoom in or out?" & RETURN & "* Zoom activation (automatic, click, or message)" & RETURN & "* Horizontal and vertical zoom coordinates" & RETURN & "* Number of zoom cycles" & RETURN & "* Time period for zoom in seconds" & RETURN & RETURN & "Set the number of zoom cycles to -1 if you want an endless loop, or to 0 if the zoom should happen only once."
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Zooms a sprite in and out. " & "The sprite can zoom in once, multiple times, or continuously."
  9. end
  10.  
  11. on beginSprite me
  12.   pZoomed = resolve(pZoomed)
  13.   pAuto = resolve(pAuto)
  14.   mInitialize(me)
  15. end
  16.  
  17. on resolve prop
  18.   case prop of
  19.     pZoomed:
  20.       choiceslist = ["In", "Out"]
  21.       lookup = [#in, #out]
  22.     pAuto:
  23.       choiceslist = ["Automatic", "Click", "Message"]
  24.       lookup = [#automatic, #click, #message]
  25.   end case
  26.   return lookup[findPos(choiceslist, prop)]
  27. end
  28.  
  29. on prepareFrame me
  30.   mUpdate(me)
  31. end
  32.  
  33. on mouseUp me
  34.   if pAuto = #click then
  35.     mActivate(me)
  36.   end if
  37. end
  38.  
  39. on mInitialize me
  40.   pSprite = sprite(me.spriteNum)
  41.   pSpriteRect = pSprite.rect
  42.   pActive = 0
  43.   pCompleteCycles = 0.5
  44.   pPeriod = pPeriodBase * 1000
  45.   pText = pSprite.member.type = #text
  46.   vTarget = point(pTargetH, pTargetV)
  47.   if pZoomed = #in then
  48.     vTargetRect = rect(vTarget, vTarget + point(1, 1))
  49.     if pText then
  50.       pSprite.quad = mRecttoQuad(vTargetRect)
  51.     else
  52.       pSprite.rect = vTargetRect
  53.     end if
  54.   end if
  55.   if pAuto = #automatic then
  56.     mActivate(me)
  57.   end if
  58. end
  59.  
  60. on mUpdate me
  61.   if pActive then
  62.     vMillis = the milliSeconds
  63.     vElapsed = vMillis - pStart
  64.     if vElapsed >= pPeriod then
  65.       pActive = 0
  66.       if pText then
  67.         pSprite.quad = mRecttoQuad(pDestRect)
  68.       else
  69.         pSprite.rect = pDestRect
  70.       end if
  71.       mCheckCycle(me)
  72.     else
  73.       vRect = pStartRect + (pDiffRect * vElapsed / pPeriod)
  74.       if pText then
  75.         pSprite.quad = mRecttoQuad(vRect)
  76.       else
  77.         pSprite.rect = vRect
  78.       end if
  79.     end if
  80.   end if
  81. end
  82.  
  83. on mActivate me
  84.   case pZoomed of
  85.     #in:
  86.       mZoomIn(me)
  87.     #out:
  88.       mZoomOut(me, point(pTargetH, pTargetV))
  89.   end case
  90. end
  91.  
  92. on mCheckCycle me
  93.   vContinue = 0
  94.   case pCycles of
  95.     (-1):
  96.       vContinue = 1
  97.     0:
  98.       vContinue = 0
  99.     otherwise:
  100.       pCompleteCycles = pCompleteCycles + 0.5
  101.       if integer(pCompleteCycles) <= pCycles then
  102.         vContinue = 1
  103.       end if
  104.   end case
  105.   if vContinue then
  106.     if pDestRect = pSpriteRect then
  107.       mZoomOut(me, point(pTargetH, pTargetV))
  108.     else
  109.       mZoomIn(me)
  110.     end if
  111.   end if
  112. end
  113.  
  114. on mRecttoQuad vRect
  115.   return [point(vRect.left, vRect.top), point(vRect.right, vRect.top), point(vRect.right, vRect.bottom), point(vRect.left, vRect.bottom)]
  116. end
  117.  
  118. on mZoomIn me
  119.   mZoom(me, pSpriteRect)
  120. end
  121.  
  122. on mZoomOut me, vTarget
  123.   mZoom(me, rect(vTarget, vTarget + point(1, 1)))
  124. end
  125.  
  126. on mZoom me, vDestRect
  127.   pActive = 1
  128.   pStartRect = pSprite.rect
  129.   pDestRect = vDestRect
  130.   pDiffRect = pDestRect - pStartRect
  131.   pStart = the milliSeconds
  132. end
  133.  
  134. on mCenter vRect
  135.   return point(vRect.left + (vRect.width / 2), vRect.top + (vRect.height / 2))
  136. end
  137.  
  138. on mZoomActivate me
  139.   if pAuto = #message then
  140.     mActivate(me)
  141.   end if
  142. end
  143.  
  144. on isOKToAttach me, aSpriteType, aSpriteNum
  145.   case aSpriteType of
  146.     #graphic:
  147.       return getPos([#text, #bitmap, #animGif, #vectorShape, #quickTimeMedia, #flash], sprite(aSpriteNum).member.type) <> 0
  148.     #script:
  149.       return 0
  150.   end case
  151. end
  152.  
  153. on getPropertyDescriptionList me
  154.   vRect = sprite(the currentSpriteNum).rect
  155.   vCenter = mCenter(vRect)
  156.   vPDList = [:]
  157.   setaProp(vPDList, #pZoomed, [#comment: "Zoom in or out?", #format: #string, #default: "In", #range: ["In", "Out"]])
  158.   setaProp(vPDList, #pAuto, [#comment: "Start automatically, when clicked, or by message?", #default: "Automatic", #format: #string, #range: ["Automatic", "Click", "Message"]])
  159.   setaProp(vPDList, #pTargetH, [#comment: "Horizontal zoom coordinate", #format: #integer, #default: vCenter.locH])
  160.   setaProp(vPDList, #pTargetV, [#comment: "Vertical zoom coordinate", #format: #integer, #default: vCenter.locV])
  161.   setaProp(vPDList, #pCycles, [#comment: "Zoom cycles (0 = one zoom only, -1 = repeat forever)", #format: #integer, #default: 0, #range: [#min: -1, #max: 10]])
  162.   setaProp(vPDList, #pPeriodBase, [#comment: "Time period for zoom (seconds)", #format: #float, #default: 2.0, #range: [#min: 0.25, #max: 15.0]])
  163.   return vPDList
  164. end
  165.